﻿using System;

public struct AudioWrapper
{
    string volumeKey;
    string muteKey;
    public Action onVolumeChanged;
    public Action onMuteChanged;

    public float Volume
    {
        get
        {
            return DataHelper.GetFloat(volumeKey, 1);
        }
        set
        {
            if (value < 0)
                value = 0;
            if (value > 1)
                value= 1;
            DataHelper.SetFloat(volumeKey, value);
            DataHelper.SaveAll();
            onVolumeChanged.Invoke();
        }
    }

    public bool Mute
    {
        get
        {
            return DataHelper.GetInt(muteKey, 0) == 1 ? true : false;
        }
        set
        {
            DataHelper.SetInt(muteKey, value ? 1 : 0);
            DataHelper.SaveAll();
            onMuteChanged.Invoke();
        }
    }

    public AudioWrapper(string key)
    {
        volumeKey = key + "volume";
        muteKey = key + "mute";
        onVolumeChanged = null;
        onMuteChanged = null;
    }
}
